//Copyright 2012 Trevin Liberty
//GNU GPL v3
//Author: Trevin Liberty
//
//Holds an X and Y position. Template. Can by used as a vector.

#ifndef POINT_H
#define POINT_H

#include <math.h>

//See comment at top of file for a complete description
template <class T>
class Point {
public:
	T x;
	T y;

	Point() : x(0), y(0) {};
	Point(T x, T y) : x(x), y(y) {};

	void normalize() {
		T length = sqrt(x*x + y*y);
		x = x/length;
		y = y/length;
	}

	float dist(Point<T> p) {
		return std::sqrt(std::pow((x - p.x), 2) + std::pow((y - p.y), 2));
	}

	Point& operator =(const Point& p) {
		if(this == &p)
			return *this;
		x = p.x;
		y = p.y;
		return *this;
	}

	operator Point<float>() {
		return Point<float>(x, y);
	}
	operator Point<int>() {
		return Point<int>(x, y);
	}

	Point operator +(const Point& p) {
		return Point<T>(x + p.x, y + p.y);
	}

	Point operator -(const Point& p) {
		return Point<T>(x - p.x, y - p.y);
	}

	Point operator *(const int i) {
		return Point<T>(x*i, y*i);
	}

	Point operator /(const int i) {
		return Point<T>(x/i, y/i);
	}

	Point operator -(const int i) {
		return Point<T>(x - i, y - i);
	}

	Point operator +(const int i) {
		return Point<T>(x+i, y+i);
	}

	const bool operator ==(const Point& p) const {
		return x == p.x && y == p.y;
	}

	const bool operator !=(const Point& p) const {
		return x != p.x && y != p.y;
	}
};

#endif